package com.hzhk.happyrent.ui.adapter.rent;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hzhk.happyrent.App;
import com.hzhk.happyrent.R;
import com.hzhk.happyrent.bean.rent.ProductListModel;
import com.hzhk.happyrent.bean.rent.RentTopModel;
import com.hzhk.happyrent.network.HttpManager;
import com.hzhk.happyrent.ui.adapter.BaseAdapter;
import com.hzhk.happyrent.utils.glide.ShowImageUtils;

import butterknife.BindView;
import butterknife.ButterKnife;


public class HorizontalHomeAdapter extends BaseAdapter<ProductListModel.DataBean.GoodsBean> {

    public HorizontalHomeAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_home_pic, null);
            viewHolder=new ViewHolder(convertView);
            viewHolder.setData(mList.get(position));
            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
            viewHolder.setData(mList.get(position));
        }
        return convertView;
    }

    class ViewHolder {
        @BindView(R.id.home_top_pic)
        ImageView homeTopPic;
        @BindView(R.id.home_top_title)
        TextView homeTopTitle;
        @BindView(R.id.home_top_unit_price)
        TextView homeTopUnitPrice;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
        public void setData(ProductListModel.DataBean.GoodsBean goodsBean){
            ShowImageUtils.showImageViewToCircleNoPlaceHolder(App.getContext(),goodsBean.getGoodsImage(),homeTopPic,10);
            homeTopTitle.setText(goodsBean.getGoodsName());
            if(!TextUtils.isEmpty(goodsBean.getPrice())){
                if(goodsBean.getPrice().contains(".")){
                    homeTopUnitPrice.setText(getString(R.string.price_lg)+goodsBean.getPrice().substring(0,goodsBean.getPrice().indexOf("."))+getString(R.string.price_unit));
                }else{
                    homeTopUnitPrice.setText(getString(R.string.price_lg)+goodsBean.getPrice()+getString(R.string.price_unit));
                }
            }

        }
    }
}
